package master

import (
	"github.com/hwcer/cosgo/registry"
	"github.com/hwcer/yyds/config"
	"github.com/hwcer/yyds/context"
	"strconv"
	"strings"
)

func init() {
	Register(&items{})
}

type items struct {
	Name  string `json:"name"`
	Label string `json:"label"`
}

func (this *items) Caller(node *registry.Node, handle *context.Context) interface{} {
	f := node.Method().(func(*items, *context.Context) interface{})
	return f(this, handle)
}

// Config  道具配置信息
func (this *items) Config(c *context.Context) interface{} {
	r := map[int32]items{}
	t := c.GetString("t")
	for id, v := range config.Config.ITypes {
		label := strconv.Itoa(int(id))
		if t == "" || strings.HasPrefix(label, t) {
			r[id] = items{Name: v.Name, Label: label}
		}
	}
	return r
}
